package com.os.lambda.chapter6;

import com.os.lambda.chapter3.StringLine;
import com.os.lambda.chapter3.Track;
import com.os.lambda.chapter5.Album;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

public class Chapter6 {

    public static void main(String[] args) {


        System.out.println(StringLine.STRING_LINE);


    }

    /**
     * 串行化计算专辑曲目长度
     */
    public int serialArraySum(List<Album> albums){
        return albums.stream()
                .flatMap(Album::getTracks)
                .mapToInt(Track::getNum)
                .sum();
    }

    /**
     * 并行化计算专辑曲目长度
     */
    public int parallelArraySum(List<Album> albums){
        return albums.parallelStream()
                .flatMap(Album::getTracks)
                .mapToInt(Track::getNum)
                .sum();
    }


}
